/**
 * This class is a subclass of the Hand class, and are used to model a hand of Flush.
 * It overrides getTopCard,isValid and getType method that it inherits from Hand class.
 *
 * @author Jiang Feiyu
 *
 */
public class Flush extends Hand{
    /**
     * Constructor for Flush type hand. Calls the constructor of Hand superclass.
     *
     * @param player Player who plays the hand
     * @param cards  List of card played by the player
     */
    public Flush(CardGamePlayer player, CardList cards) {
        super(player, cards);
    }
    /**
     * Returns the top card of the hand.
     */
    public Card getTopCard() {
        int returnIndex = 0;
        int largest_card = 0;
        for(int i = 0;i < 5;i ++) {
            int this_rank = 0;
            if (this.getCard(i).getRank() == 0){
                this_rank = 13;
            }
            if (this.getCard(i).getRank() == 1){
                this_rank = 14;
            }
            if (this_rank > largest_card){
                largest_card = this_rank;
                returnIndex = i;
            }
        }
        return this.getCard(returnIndex);
    }
    /**
     * Checks whether the hand is a Flush.
     */
    public boolean isValid() {
        if(this.size() == 5) {
            for(int i = 0;i < 4;i ++) {
                if(i == 3) {
                    return (this.getCard(i).getSuit() == this.getCard(i + 1).getSuit());
                }
                if (this.getCard(i).getSuit() != this.getCard(i + 1).getSuit()){
                    return false;
                }
            }
        }else{
            return false;
        }
        return false;
    }
    /**
     * Returns type of string.
     */
    public String getType() {
        return "Flush";
    }
}
